home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XAAES_S.ZIP / XAAES / TESTAPP / LINES.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-13  |  4.0 KB  |  199 lines

  1. /*
  2.     Primitive command line console for XaAES
  3.     - No terminal emulation at all.....
  4. */
  5.  
  6. #include <AES.H>
  7. #include <VDI.H>
  8.  
  9. typedef struct tri {
  10.     short x1,y1;
  11.     short x2,y2;
  12.     short x3,y3;
  13.     short a,b;
  14. } TRI;
  15.  
  16. short my_handle,ap_id;
  17. short w_id1;
  18. GRECT dirty;
  19.  
  20. void draw_triangles(TRI *t,short cnt,short bgd)
  21. {
  22.     short *tpnt=(short*)t;
  23.     short x,y,w,h,wx,wy,ww,wh,clip[4],pnt[4];
  24.     short f;
  25.     GRECT walk;
  26.  
  27.     for(f=0; f<cnt; f++)
  28.     {
  29.         t[f].a=t[f].x1;
  30.         t[f].b=t[f].y1;
  31.     }
  32.  
  33.     wind_update(BEG_UPDATE);
  34.     wind_get(w_id1, WF_WORKXYWH, &wx, &wy, &ww, &wh);
  35.     walk.g_x=wx;
  36.     walk.g_y=wy;
  37.     walk.g_w=ww;
  38.     walk.g_h=wh;
  39.     pnt[0]=wx; pnt[1]=wy; pnt[2]=wx+ww; pnt[3]=wy+wh;
  40.     wind_get(w_id1, WF_FIRSTXYWH, &x, &y, &w, &h);
  41.     rc_intersect(&walk,&dirty);
  42.     graf_mouse(M_OFF, NULL);
  43.     while(h)
  44.     {
  45.         walk.g_x=x;
  46.         walk.g_y=y;
  47.         walk.g_w=w;
  48.         walk.g_h=h;
  49.         if (rc_intersect(&dirty,&walk))
  50.         {
  51.             clip[0]=walk.g_x; clip[1]=walk.g_y;
  52.             clip[2]=walk.g_x+walk.g_w; clip[3]=walk.g_y+walk.g_h;
  53.             vs_clip(my_handle, 1, clip);
  54.  
  55.             if (bgd)
  56.                 v_bar(my_handle,pnt);
  57.             
  58.             vsl_color(my_handle, LWHITE);
  59.             v_pline(my_handle, 4, tpnt);
  60.             
  61.             for(f=1; f<cnt-1; f++)
  62.             {
  63.                 tpnt+=sizeof(TRI);
  64.                 vsl_color(my_handle, f);
  65.                 v_pline(my_handle, 4, tpnt);
  66.             }
  67.         }
  68.         wind_get(w_id1, WF_NEXTXYWH, &x, &y, &w, &h);
  69.     }
  70.     vs_clip(my_handle, 0, clip);
  71.     graf_mouse(M_ON, NULL);
  72.     wind_update(END_UPDATE);
  73. }
  74.  
  75. void main(int argc, char *argv[])
  76. {
  77.     short work_in[11]={1,1,1,1,1,1,1,1,1,1,2};
  78.     short work_out[57];
  79.     short msg[16],x,y,w,h,wx,wy,ww,wh,*ta,*tb;
  80.     short dummy=0, open_windows=1;
  81.     short f,e,evx,evy,a,kc_shstate,kc_key,click_count;
  82.     TRI this={10,10,10,20,20,10,0,0},old[10],dir={-4,16,-5,-2,5,3,0,0};
  83.     
  84.     ta=(short*)&old;
  85.     for(f=0; f<10*8; f++)
  86.         ta[f]=-1;
  87.     
  88.     ap_id=appl_init();
  89.     
  90.     my_handle=graf_handle(&x,&y,&w,&h);        // Open a virtual workstation
  91.     v_opnvwk(work_in,&my_handle,work_out);
  92.     vsf_color(my_handle,LWHITE);
  93.     vsf_interior(my_handle, FIS_SOLID);
  94.     vswr_mode(my_handle, MD_TRANS);
  95.     
  96.     wind_calc(0,NAME|CLOSE|MOVER|FULLER|SIZER,0,0,100,100,&wx,&wy,&ww,&wh);
  97.     
  98.     w_id1=wind_create(NAME|CLOSE|MOVER|FULLER|SIZER, wx,wy,ww,wh);
  99.  
  100.     wind_set(w_id1,WF_NAME, ADDR("XaAES Lines"));
  101.  
  102.     wind_open(w_id1,20,40,ww,wh);
  103.  
  104.     while(open_windows)
  105.     {
  106.         e=evnt_multi(MU_MESAG|MU_TIMER,258,3,0,0,0,0,0,0,0,0,0,0,0,
  107.             msg,5,0,&evx,&evy,&a,&kc_shstate,&kc_key,&click_count);
  108.  
  109.         if (e&MU_MESAG)
  110.         {
  111.             dummy=msg[0];
  112.             switch(dummy)
  113.             {
  114.                 case WM_CLOSED:    // did someone close one of our windows?
  115.                     wind_close(msg[3]);
  116.                     open_windows=0;
  117.                     break;
  118.                 case WM_SIZED:
  119.                 case WM_MOVED:
  120.                     wind_set(msg[3], WF_CURRXYWH,msg[4], msg[5], msg[6], msg[7]);
  121.                     break;
  122.                 case WM_REDRAW:
  123.                     dirty.g_x=msg[4];
  124.                     dirty.g_y=msg[5];
  125.                     dirty.g_w=msg[6];
  126.                     dirty.g_h=msg[7];                    
  127.                     draw_triangles(old,5,1);
  128.                     break;
  129.                 case WM_FULLED:
  130.                     wind_get(msg[3], WF_FULLXYWH, &x, &y, &w, &h);
  131.                     wind_get(msg[3], WF_CURRXYWH, &wx, &wy, &ww, &wh);
  132.                     if ((((x==wx)&&(y==wy))&&(w==ww))&&(h==wh))
  133.                         wind_get(msg[3], WF_PREVXYWH, &x, &y, &w, &h);
  134.                     wind_set(msg[3], WF_CURRXYWH, x, y, w, h);
  135.                     break;
  136.                 case WM_TOPPED:
  137.                     wind_set(msg[3], WF_TOP, 0, 0, 0, 0);
  138.                     break;
  139.                 case WM_BOTTOMED:
  140.                     wind_set(msg[3], WF_BOTTOM, 0, 0, 0, 0);
  141.                     break;
  142.             }
  143.         }
  144.         
  145.         if (e&MU_TIMER)
  146.         {
  147.             wind_get(w_id1, WF_WORKXYWH, &wx, &wy, &ww, &wh);
  148.             ta=(short*)&this;
  149.             tb=(short*)&dir;
  150.             for(f=0; f<8; f+=2)
  151.             {
  152.                 ta[f]+=tb[f];
  153.                 if (ta[f]<wx)
  154.                 {
  155.                     tb[f]=-tb[f];
  156.                     ta[f]=wx;
  157.                 }
  158.                 if (ta[f]>wx+ww)
  159.                 {
  160.                     tb[f]=-tb[f];
  161.                     ta[f]=wx+ww;
  162.                 }
  163.             }
  164.             for(f=1; f<8; f+=2)
  165.             {
  166.                 ta[f]+=tb[f];
  167.                 if (ta[f]<wy)
  168.                 {
  169.                     tb[f]=-tb[f];
  170.                     ta[f]=wy;
  171.                 }
  172.                 if (ta[f]>wy+wh)
  173.                 {
  174.                     tb[f]=-tb[f];
  175.                     ta[f]=wy+wh;
  176.                 }
  177.             }
  178.  
  179.             for(f=0; f<9; f++)
  180.                 old[f]=old[f+1];
  181.             
  182.             old[9]=this;
  183.  
  184.             dirty.g_x=wx;
  185.             dirty.g_y=wy;
  186.             dirty.g_w=ww;
  187.             dirty.g_h=wh;
  188.             
  189.             draw_triangles(old,5,0);
  190.         }
  191.             
  192.             
  193.     }
  194.     
  195.     v_clsvwk(my_handle);
  196.         
  197.     appl_exit();
  198. }
  199.